Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
how to sort this two sub array [ { [ ] } ,{ [ ] } , { [ ] } ,] in javascript

how can i sort this tests array based on discount_price i have sorted only the lab_partners array,,,can anyone tell me how to sort the main array nd so that array should look something like : 200 ,250, 299 ,500 so my array is something like this - [ { [ ] } ,{ [ ] } , { [ ] } ,]

"tests": [
 {
   "id": 11,
  "habit_test_id": 3,
  "test_id": 1,
  "test": {
           "id": 1,
            "test_name": "Blood Test",
          },
   "lab_partners": [
  {
     "id": 1,
    "discounted_price": 250, 
  },
  {
     "id": 7,
     "discounted_price": 299,

    }
   ]
 },
 {

 "test": {
     "id": 4,
     "test_name": "MRI",

      },
 "lab_partners": [
     {
    "id": 6,

   "discounted_price": 500,

  },
  {
    "id": 6,

   "discounted_price": 200,

  }
 ]
 }
]
}

//this only sort the lab_partners array i want to sort on the basis of both test array

 const condition_based=   tests.map((itr, idx) =>
  itr.lab_partners.sort((firstItem, secondItem) => ( firstItem.discounted_price - 
  secondItem.display_price)));
  console.log(condition_based,'condition_based');
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I don't really know what you are trying to achieve, or what you expect from this array, but please look into this

https://www.w3schools.com/JS/js_object_constructors.asp

It seems to me like there are some similarities in all the object values, and you are missing out some maybe just because they are null values.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda